package com.bilibili.server.dto;

import lombok.Data;

@Data
public class Response<T> {
    private Integer code;
    private String message;
    private T data;
    private String error;

    public Response() {}

    public Response(Integer code, String message, T data) {
        this.code = code;
        this.message = message;
        this.data = data;
    }

    public Response(Integer code, String message, T data, String error) {
        this.code = code;
        this.message = message;
        this.data = data;
        this.error = error;
    }

    // 成功响应
    public static <T> Response<T> success(String message, T data) {
        return new Response<>(200, message, data);
    }

    public static <T> Response<T> success(T data) {
        return new Response<>(200, "操作成功", data);
    }

    public static <T> Response<T> success(String message) {
        return new Response<>(200, message, null);
    }

    // 创建成功响应
    public static <T> Response<T> created(String message, T data) {
        return new Response<>(201, message, data);
    }

    // 错误响应
    public static <T> Response<T> error(Integer code, String message) {
        return new Response<>(code, message, null);
    }

    public static <T> Response<T> error(Integer code, String message, String error) {
        return new Response<>(code, message, null, error);
    }
}